package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.Food;
import com.k.demo.entity.Notice;
import com.k.demo.mapper.NoticeMapper;
import com.k.demo.service.NoticeService;

@Service
public class NoticeServiceImpl implements NoticeService{

	@Autowired
	private NoticeMapper noticeMapper;
	
	public List<Notice> getAll(){
		return noticeMapper.selectAll();
	}
	
	public Notice showNotice() {
		return noticeMapper.selectShow();
	}

	//分页显示
	public PageInfo<Notice> getpage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum,pageSize);
		return new PageInfo<Notice>(noticeMapper.selectAll());
	}

	//单个删除
	public boolean deleteById(int id) {
		int count = noticeMapper.falseDeleteNotice(id);
		
		if(count > 0 ) {
			return true;
		}
		return false;
	}

	//批量删除
	public boolean deleteByGroup(List<Integer> list) {

		
		return noticeMapper.deleteByGroup(list);
		
	}

	//公告新增
	public Notice addNotice(Notice notice) {
		
		int count = noticeMapper.addNotice(notice);
		
		if(count>0) {
			
			return notice;
			
		}
		
		return null;
	}

	//公告修改
	public Notice modifyNotice(Notice notice) {
		
		int count = noticeMapper.updateNotice(notice);
		
		if (count > 0) {
			
			return notice;
			
		}
		
		return null;
	}

	//公告内容模糊查找
	public PageInfo<Notice> getpagebyname(int pageNum, int pageSize, String notice_content) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<Notice>(noticeMapper.selectByName(notice_content));
	}

	//公告时间区间查找
	public PageInfo<Notice> getpagebytime(int pageNum, int pageSize, String time1, String time2) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<Notice>(noticeMapper.selectByTime(time1, time2));
	}

	//撤销公告
	public int revokeNotice(int notice_id) {
		
		return noticeMapper.revokeNotice(notice_id);
	}

	//修改某个通知的状态
	public int modifyState(int notice_id) {
		
		return noticeMapper.modifyState(notice_id);
	}

	//修改所有通知的状态
	public int modifyAllStatus() {
		return noticeMapper.modifAllState();
	}
	
	
	
	

}
